<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <ul>
        <li><router-link to="/home">Home</router-link></li>
        <li><router-link to="/user/100?aaa=200">用户100</router-link></li>
      </ul>
      <router-view></router-view>
    </div>
    <script src="vue.js"></script>
    <script src="vue-router.js"></script>
    <script>
      const Home = {
        template: `<div>Home</div>`,
      };
      const User = {
        props:['userId','age','aaa'],
        template:`
        <div>
          <p>User {{userId}}</p>
          <p>aaa {{aaa}}</p>
          <p>Age {{age}}</p>
        </div>`
      }
      const routes = [
        { name: "home", path: "/home", component: Home },
        { 
          name: "user", 
          path: "/user/:userId", 
          component: User,
          //如果 props 被设置为 true，route.params 将会被设置为组件属性。
          //props:true userId赋值
          //props:{age:100},// //age赋值，但是userId 就没有值了
          props:route=>({
              age:18,
              ...route.params,
              ...route.query
          })

        }
      ];

      var router = new VueRouter({
        routes,
      });
      var vm = new Vue({
        el: "#app",
        router,
      });
    </script>
  </body>
</html>
